home *** CD-ROM | disk | FTP | other *** search
/ Computer Select (Limited Edition) / Computer Select.iso / dobbs / v17n04 / handprin.urc / (InkEdit) / InkDoc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-03-01  |  2.8 KB  |  102 lines  |  [TEXT/KAHL]

  1. #include <Global.h>
  2. #include <Commands.h>
  3. #include <CApplication.h>
  4. #include <CBartender.h>
  5. #include <CDataFile.h>
  6. #include <CDecorator.h>
  7. #include <CDesktop.h>
  8. #include <CError.h>
  9. #include <CPanorama.h>
  10. #include <CScrollPane.h>
  11. #include <TBUtilities.h>
  12. #include "InkDoc.h"
  13. #include "InkPane.h"
  14. #include "CWindow.h"
  15.  
  16. #define    WINDculture        500        /* Resource ID for WIND template */
  17.  
  18. extern    CApplication *gApplication;    /* The application */
  19. extern    CBartender    *gBartender;    /* The menu handling object */
  20. extern    CDecorator    *gDecorator;    /* Window dressing object    */
  21. extern    CDesktop    *gDesktop;        /* The enclosure for all windows */
  22. extern    CBureaucrat    *gGopher;        /* The current boss in the chain of command */
  23. extern    OSType        gSignature;        /* The application's signature */
  24. extern    CError        *gError;        /* The error handling object */
  25.  
  26. void InkDoc::IEditDoc(CApplication *aSupervisor, Boolean printable) {
  27.     CDocument::IDocument(aSupervisor, printable);
  28.     }
  29.  
  30. void InkDoc::NewFile(void) {
  31.     BuildWindow(NULL);
  32.     itsWindow->Select();
  33.     }
  34.  
  35. void InkDoc::OpenFile(SFReply *macSFReply) {
  36.     CDataFile    *theFile;
  37.     Handle        theData;
  38.     Str63        theName;
  39.     OSErr        theError;
  40.     theFile = new(CDataFile);
  41.     itsFile = theFile;
  42.     theFile->IDataFile();
  43.     theFile->SFSpecify(macSFReply);
  44.     theFile->Open(fsRdWrPerm);
  45.     theData = theFile->ReadAll();     /* ReadAll() creates the handle */
  46.     BuildWindow(theData);
  47.     DisposHandle(theData);
  48.     itsFile->GetName(theName);
  49.     itsWindow->SetTitle(theName);
  50.     itsWindow->Select();            /* Don't forget to make the window active */
  51.     }
  52.  
  53. void InkDoc::BuildWindow (Handle theData) {
  54.     CScrollPane        *theScrollPane;
  55.     InkPane        *theMainPane;
  56.     Rect            margin;
  57.     itsWindow = new(CWindow);
  58.     itsWindow->IWindow(WINDculture, FALSE, gDesktop, this);
  59.     theScrollPane = new(CScrollPane);
  60.     theScrollPane->IScrollPane(itsWindow, this, 10, 10, 0, 0,
  61.                                 sizELASTIC, sizELASTIC,
  62.                                 TRUE, TRUE, TRUE);
  63.     theScrollPane->FitToEnclFrame(TRUE, TRUE);
  64.     theMainPane = new(InkPane);
  65.     itsMainPane = theMainPane;
  66.     itsGopher = theMainPane;
  67.     theMainPane->IEditPane(theScrollPane, this);
  68.     theScrollPane->InstallPanorama(theMainPane);
  69.     if (theData)
  70.         theMainPane->SetData(theData);
  71.     gDecorator->PlaceNewWindow(itsWindow);
  72.     }
  73.  
  74. Handle GetFlatData(List *Data);
  75.  
  76.  
  77. Boolean InkDoc::DoSave(void) {
  78.     Handle        theData;
  79.  
  80.     if (itsFile == NULL)
  81.         return(DoSaveFileAs());
  82.     else {
  83.         theData = GetFlatData(((InkPane*)itsMainPane)->Data);
  84.         ((CDataFile *)itsFile)->WriteAll(theData);            
  85.         dirty = FALSE;                    /* Document is no longer dirty        */
  86.         gBartender->DisableCmd(cmdSave);
  87.         return(TRUE);                    /* Save was successful                */
  88.         }
  89.     }
  90.  
  91. Boolean InkDoc::DoSaveAs(SFReply *macSFReply) {
  92.     if (itsFile != NULL)
  93.         itsFile->Dispose();
  94.     itsFile = new(CDataFile);
  95.     ((CDataFile *)itsFile)->IDataFile();
  96.     itsFile->SFSpecify(macSFReply);
  97.     itsFile->CreateNew(gSignature, 'INKd');
  98.     itsFile->Open(fsRdWrPerm);
  99.     itsWindow->SetTitle(macSFReply->fName);
  100.     return( DoSave() );
  101.     }
  102.